package logic

import (
	"context"
	"house_srv/housesrv"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddHouseLogic {
	return &AddHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddHouseLogic) AddHouse(req *types.AddHouseRequest) (resp *types.Response, err error) {
	house, err := l.svcCtx.HouseSrv.AddHouse(l.ctx, &housesrv.AddHouseRequest{
		Name:    req.Name,
		Address: req.Address,
		Types:   req.Types,
		Size:    float32(req.Size),
		Price:   float32(req.Price),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: 200,
		Msg:  "房源发布成功",
		Data: map[string]interface{}{
			"HouseId": house,
		},
	}, nil
}
